<template>
  <div>
    <el-table
      :data="manageList"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <el-table-column prop="id" label="角色编号"> </el-table-column>
      <el-table-column prop="username" label="角色名称"> </el-table-column>
      <el-table-column prop="rolename" label="所属角色"> </el-table-column>
      <el-table-column label="状态">
        <template slot-scope="scope">
          <div>
            <el-button v-if="scope.row.status == 1" type="danger">
              启用
            </el-button>
            <el-button v-else type="success"> 禁用 </el-button>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <div>
            <el-button @click="dit(scope.row.uid)">编辑</el-button>
            <v-del @del="del(scope.row.uid)"></v-del>
          </div>
        </template>
      </el-table-column>
    </el-table>
    {{managesize}}
    {{managetotal}}
    <el-pagination background layout="prev, pager, next" :total="managetotal" :page-size="managesize" @current-change="change">
    </el-pagination>
  </div>
</template>
<script>
import { successAlert, warningAlert } from "../../../util/alter";
import { mapGetters, mapActions } from "vuex";
//引入删除接口
import { manageDel } from "../../../requster/api";
import vDel from "../../../components/del.vue"
export default {
    components:{
        vDel
    },
  data() {
    return {};
  },

  methods: {
    ...mapActions({
      reqmanagelist: "manage/reqchangelist",
      reqmanagetotal:"manage/reqchangetotal",
      reqmanagepage:"manage/reqchangepage",
    }),
    change(num){
        this.reqmanagepage(num)
    },

    // 删除事件
    del(uid) {
     console.log(123);
          manageDel({uid:uid}).then((res) => {
            if (res.data.code == 200) {
              successAlert(res.data.msg);
              //  重新渲染页面
              this.reqmanagelist();
            } else {
              warningAlert(res.data.msg);
            }
          });
        
        
    },
    // 编辑事件
    dit(uid) {
      this.$emit("dit", uid);
    },
  },

  computed: {
    ...mapGetters({
      manageList: "manage/list",
      managetotal:"manage/total",
      managesize:"manage/size"
    }),
  },
  mounted() {
    // this.reqmanagelist();
    this.reqmanagetotal();
    this.reqmanagepage(1)
  },
};
</script>

<style>
</style>